<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Validation class for validating that two passwords match
 *
 * @category    RedCross
 * @package     RedCross_Validate
 */
class RedCross_Validate_PasswordVerification extends Zend_Validate_Abstract
{
    /**
     * Validation failure message key for when the passwords do not match
     * @var string
     */
    const NOT_MATCH = 'notMatch';

    /**
     * Validation failure message template definitions
     * @var array
     */
    protected $_messageTemplates = array(
        self::NOT_MATCH  =>  "Passordene er ikke de samme"
    );

    /**
     * (non-PHPdoc)
     * @see library/Zend/Validate/Zend_Validate_Interface#isValid($value)
     */
    public function isValid($value, $context = null)
    {
        $value = (string) $value;
        $this->_setValue($value);

        if (is_array($context)) {
        	if (isset($context['password']) && ($value == $context['password'])) {
        		return true;
        	}
        } else if (is_string($context) && ($value == $context)) {
        	return true;
        }

        $this->_error(self::NOT_MATCH);
        return false;
    }
}